package com.rmb.mart.entity.api;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.rmb.common.validated.AddGroup;
import com.rmb.common.validated.UpdateGroup;
import com.rmb.mart.qurey.QueryPage;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.io.Serializable;
import java.util.Date;

/**
 * (MartApiEssential)实体类
 *
 * @author makejava
 * @since 2021-01-20 09:37:33
 */

@Data
@Entity
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Table(name = "mart_api_essential")
public class MartApiEssential extends QueryPage implements Serializable {
    private static final long serialVersionUID = 954476052470143034L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Null(message = "新增不能指定id",groups = {AddGroup.class})
    @NotNull(message = "修改必须指定id",groups = {UpdateGroup.class})
    private Long id;
    /**
     * 接口名称
     */
    @NotEmpty(message = "接口名称不能为空",groups = {AddGroup.class,UpdateGroup.class})
    private String name;

    /**
     * 接口描述
     */
    @NotEmpty(message = "接口描述不能为空",groups = {AddGroup.class})
    private String description;
    /**
     * 简介
     */
    @Column(name = "breif_introduction")
    @NotEmpty(message = "接口简介不能为空",groups = {AddGroup.class})
    private String briefIntroduction;
    /**
     * 接口图片
     */
    private String picture;
    /**
     * 接口来源
     */
    @Column(name = "user_company_id")
    @NotNull(message = "公司id不能为空！",groups = {AddGroup.class,UpdateGroup.class})
    private Long userCompanyId;
    /**
     * 更新周期
     */
    @Column(name = "replace_cycle")
    private Integer replaceCycle;
    /**
     * 接口使用量
     */
    @Column(name = "usage_amount")
    private Long usageAmount;
    /**
     * 申请状态 0-待审核 1-审核中 2-审核通过
     */
    private Long status;
    /**
     * 类型ID
     */
    @Column(name = "mart_api_type_id")
    @NotNull(message = "类型id不能为空！",groups = {AddGroup.class,UpdateGroup.class})
    private Long martApiTypeId;
    /**
     * 接口地址
     */
    private String url;
    /**
     * 请求参数
     */
    @Column(name = "request_parameter")
    private String requestParameter;
    /**
     * 请求方式
     */
    @Column(name = "way_to_request")
    private String wayToRequest;
    /**
     * 返回格式
     */
    @Column(name = "return_format")
    private String returnFormat;

    /**
     * 接口状态 接口状态 0-禁用 1-启用 2-注销
     */
    @Column(name = "api_state")
    private Long apiState;

    /**
     * 接口金额
     */
    private Double money;

    /**
     * 创建人
     */
    @Column(name = "create_by")
    private String createBy;
    /**
     * 创建时间
     */
    @Column(name = "create_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss" )
    private Date createTime;
    /**
     * 修改人
     */
    @Column(name = "update_by")
    private String updateBy;
    /**
     * 修改时间
     */
    @Column(name = "update_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss" )
    private Date updateTime;


    /**
     * 次数限制
     */
    @Transient
    private Integer timesLimit;

    /**
     * 成功次数
     */
    @Transient
    private Integer trueNum;

    /**
     * 失败次数
     */
    @Transient
    private Integer falseNum;
    /**
     * 接口平均响应时间
     */
    @Transient
    private Integer averageResponseTime;
}